<script>
  import { useStore } from 'vuex'
  import { computed } from 'vue'
  export default function () {
    const diagnosisType = [
      { value: 1, label: '首诊' },
      { value: 0, label: '复诊' },
    ]
    const emrType = { 默认病历: '1', 哮喘病历: '2' }
    const emrStatus = { 诊治中: '', 已停药: '' }
    // 默认病例初始化
    const mrForm = function () {
      return {
        treatmentType: null,
        morbidityTime: null,
        mainSuit: null,
        historyPresent: null,
        past: null,
        allergy: null,
        personal: null,
        family: null,
        signs: null,
        auxiliaryExamination: null,
        diagnosis: [],
        treatmentOpinion: null,
        followDate: null,
        files: null,
      }
    }

    // 控制级别
    const controlLevels = [
      { label: '未控制', value: '未控制' },
      { label: '部分控制', value: '部分控制' },
      { label: '良好控制', value: '良好控制' },
      { label: '完全控制', value: '完全控制' },
    ]

    // 急性专用的控制级别 acuteControlLevels
    const acuteControlLevels = [
      { label: '轻度', value: '轻度' },
      { label: '中度', value: '中度' },
      { label: '重度', value: '重度' },
      { label: '危重度', value: '危重度' },
    ]
    // 修改急性时
    const fitterControlLevels = computed(() => {
      return (form) => {
        if (form.treatmentPlanType === '当前急性发作治疗方案') {
          return acuteControlLevels
        }
        return controlLevels
      }
    })

    const fitterControlLevelsFunc = (name) => {
      if (isAcute(name)) {
        return acuteControlLevels
      }
      return controlLevels
    }

    const isAcuteTitle = (treatmentPlanType) => {
      if (isAcute(treatmentPlanType)) {
        return '严重程度：'
      }
      return '控制级别：'
    }

    const isAcute = function (treatmentPlanType) {
      if (treatmentPlanType === '当前急性发作治疗方案') {
        return true
      }
      return false
    }

    // 治疗方案
    const treatmentPlans = computed(() => {
      return function (type) {
        if (type === '简易版') {
          return [
            { label: '控制药物治疗方案', value: '控制药物治疗方案' },
            { label: '当前急性发作治疗方案', value: '当前急性发作治疗方案' },
            { label: '整体治疗方案', value: '整体治疗方案' },
          ]
        } else {
          return [
            { label: '控制药物治疗方案', value: '控制药物治疗方案' },
            { label: '缓解药物治疗方案', value: '缓解药物治疗方案' },
            { label: '当前急性发作治疗方案', value: '当前急性发作治疗方案' },
            { label: '整体治疗方案', value: '整体治疗方案' },
          ]
        }
      }
    })

    const usages = [
      {
        id: 1,
        termChs: '口服',
        termLatinAbbr: 'po',
        termLatin: 'po',
        type: 'USAGE',
        attribute: null,
        numericalValue: null,
      },
      {
        id: 2,
        termChs: '鼻喷',
        termLatinAbbr: null,
        termLatin: null,
        type: 'USAGE',
        attribute: null,
        numericalValue: null,
      },
      {
        id: 3,
        termChs: '雾化吸入',
        termLatinAbbr: null,
        termLatin: null,
        type: 'USAGE',
        attribute: null,
        numericalValue: null,
      },
      {
        id: 4,
        termChs: '注射',
        termLatinAbbr: '',
        termLatin: '',
        type: 'USAGE',
        attribute: null,
        numericalValue: null,
      },
      {
        id: 5,
        termChs: '滴鼻',
        termLatinAbbr: null,
        termLatin: null,
        type: 'USAGE',
        attribute: null,
        numericalValue: null,
      },
      {
        id: 6,
        termChs: '吸入',
        termLatinAbbr: '',
        termLatin: '',
        type: 'USAGE',
        attribute: null,
        numericalValue: null,
      },
    ]
    const frequencys = [
      {
        id: 3,
        termChs: '每日一次',
        termLatinAbbr: 'qd',
        termLatin: 'qd',
        type: 'FREQUENCY',
        attribute: '1',
        numericalValue: 1,
      },
      {
        id: 1,
        termChs: '每日两次',
        termLatinAbbr: 'bid',
        termLatin: 'bid',
        type: 'FREQUENCY',
        attribute: '1',
        numericalValue: 2,
      },
      {
        id: 2,
        termChs: '每日两至三次',
        termLatinAbbr: '每日两至三次',
        termLatin: '每日两至三次',
        type: 'FREQUENCY',
        attribute: '1',
        numericalValue: 4,
      },
      {
        id: 4,
        termChs: '每日三次',
        termLatinAbbr: 'tid',
        termLatin: 'tid',
        type: 'FREQUENCY',
        attribute: '1',
        numericalValue: 3,
      },
      {
        id: 2,
        termChs: '每日三至四次',
        termLatinAbbr: '每日三至四次',
        termLatin: '每日三至四次',
        type: 'FREQUENCY',
        attribute: '1',
        numericalValue: 4,
      },
      {
        id: 2,
        termChs: '每日四次',
        termLatinAbbr: 'qid',
        termLatin: 'qid',
        type: 'FREQUENCY',
        attribute: '1',
        numericalValue: 4,
      },
      {
        id: 5,
        termChs: '每小时一次',
        termLatinAbbr: 'qh',
        termLatin: 'qh',
        type: 'FREQUENCY',
        attribute: '1',
        numericalValue: 24,
      },
      {
        id: 6,
        termChs: '每两小时一次',
        termLatinAbbr: 'q2h',
        termLatin: 'q2h',
        type: 'FREQUENCY',
        attribute: '1',
        numericalValue: 12,
      },
      {
        id: 7,
        termChs: '每四小时一次',
        termLatinAbbr: 'q4h',
        termLatin: 'q4h',
        type: 'FREQUENCY',
        attribute: '1',
        numericalValue: 6,
      },
      {
        id: 8,
        termChs: '每六小时一次',
        termLatinAbbr: 'q6h',
        termLatin: 'q6h',
        type: 'FREQUENCY',
        attribute: '1',
        numericalValue: 4,
      },
      {
        id: 9,
        termChs: '每八小时一次',
        termLatinAbbr: 'q8h',
        termLatin: 'q8h',
        type: 'FREQUENCY',
        attribute: '1',
        numericalValue: 3,
      },
      {
        id: 10,
        termChs: '每晚一次',
        termLatinAbbr: 'qn',
        termLatin: 'qn',
        type: 'FREQUENCY',
        attribute: '1',
        numericalValue: 1,
      },
      {
        id: 11,
        termChs: '隔日一次',
        termLatinAbbr: 'qod',
        termLatin: 'qod',
        type: 'FREQUENCY',
        attribute: '1',
        numericalValue: 0.7,
      },
      {
        id: 12,
        termChs: '每周两次',
        termLatinAbbr: 'biw',
        termLatin: 'biw',
        type: 'FREQUENCY',
        attribute: '1',
        numericalValue: 0.29,
      },
      {
        id: 13,
        termChs: '临睡前',
        termLatinAbbr: 'hs',
        termLatin: 'hs',
        type: 'FREQUENCY',
        attribute: '1',
        numericalValue: 1,
      },
      {
        id: 14,
        termChs: '上午',
        termLatinAbbr: 'am',
        termLatin: 'am',
        type: 'FREQUENCY',
        attribute: '1',
        numericalValue: 1,
      },
      {
        id: 15,
        termChs: '必要时',
        termLatinAbbr: 'prn',
        termLatin: 'prn',
        type: 'FREQUENCY',
        attribute: '1',
        numericalValue: null,
      },
      {
        id: 16,
        termChs: '早2，晚1',
        termLatinAbbr: '早2，晚1',
        termLatin: '早2，晚1',
        type: 'FREQUENCY',
        attribute: '0',
        numericalValue: null,
      },
      {
        id: 17,
        termChs: '早3，晚2',
        termLatinAbbr: '早3，晚2',
        termLatin: '早3，晚2',
        type: 'FREQUENCY',
        attribute: '0',
        numericalValue: null,
      },
      {
        id: 18,
        termChs: '早4，晚2',
        termLatinAbbr: '早4，晚2',
        termLatin: '早4，晚2',
        type: 'FREQUENCY',
        attribute: '0',
        numericalValue: null,
      },
      {
        id: 19,
        termChs: '早6，晚4',
        termLatinAbbr: '早6，晚4',
        termLatin: '早6，晚4',
        type: 'FREQUENCY',
        attribute: '0',
        numericalValue: null,
      },
      {
        id: 20,
        termChs: '自定义',
        termLatinAbbr: '自定义',
        termLatin: '自定义',
        type: 'FREQUENCY',
        attribute: '0',
        numericalValue: null,
      },
    ]

    const hashFrequencys = {
      每日一次: 'qd',
      每日两次: 'bid',
      每日两或三次: '每日两或三次',
      每日三次: 'tid',
      每日三或四次: '每日三或四次',
      每日四次: 'qid',
      每小时一次: 'qh',
      每两小时一次: 'q2h',
      每四小时一次: 'q4h',
      每六小时一次: 'q6h',
      每八小时一次: 'q8h',
      每晚一次: 'qn',
      隔日一次: 'qod',
      每周两次: 'biw',
      临睡前: 'hs',
      上午: 'am',
      必要时: 'prn',
      '早2，晚1': '早2，晚1',
      '早3，晚2': '早3，晚2',
      '早4，晚2': '早4，晚2',
      '早6，晚4': '早6，晚4',
    }

    const templateTypes = [
      { value: '公有', label: '公有' },
      { value: '私有', label: '私有' },
    ]
    const templateTypeToInt = [
      { value: 0, label: '公有' },
      { value: 1, label: '私有' },
    ]
    const actionVersions = [
      { value: '标准版', label: '标准版' },
      { value: '简易版', label: '简易版' },
    ]

    const normalTypes = [
      { value: '整体方案', label: '整体方案' },
      { value: '部分方案', label: '部分方案' },
      { value: '主诉', label: '主诉' },
      { value: '现病史', label: '现病史' },
      { value: '既往史', label: '既往史' },
      { value: '过敏史', label: '过敏史' },
      { value: '个人史', label: '个人史' },
      { value: '家族史', label: '家族史' },
      { value: '体格检查', label: '体格检查' },
      { value: '辅助检查', label: '辅助检查' },
      { value: '治疗意见', label: '治疗意见' },
    ]

    const normalWithKey = [
      { value: 'mainSuit', label: '主诉' },
      { value: 'historyPresent', label: '现病史' },
      { value: 'past', label: '既往史' },
      { value: 'allergy', label: '过敏史' },
      { value: 'personal', label: '个人史' },
      { value: 'family', label: '家族史' },
      { value: 'signs', label: '体格检查' },
      { value: 'auxiliaryExamination', label: '辅助检查' },
      { value: 'treatmentOpinion', label: '治疗意见' },
    ]

    const asthmaActionPlanTips = {
      greenTitle:
        '【绿区】哮喘控制良好（请坚持每日使用控制药物（C-Controller），预防哮喘发作）:',
      yellowTitle:
        '【黄区】哮喘加重先兆（立即使用以下缓解药物 (R-Reliever)，并升级每日控制药物）:',
      redTitle:
        '【红区】哮喘急性发作（哮喘急性发作，请立即使用以下药物，并立即就医或拨打急救电话）:',
    }

    function findTermChs(termLatinAbbr) {
      // frequencys
      const item = frequencys.filter(
        (item) => item.termLatinAbbr === termLatinAbbr
      )
      console.log('item =' + JSON.stringify(item))
      if (item.length > 0) return item[0].termChs
      return termLatinAbbr
    }
    return {
      diagnosisType,
      emrType,
      emrStatus,
      mrForm,
      frequencys,
      usages,
      // 简易
      treatmentPlans,
      controlLevels,
      templateTypes,
      actionVersions,
      normalTypes,
      templateTypeToInt,
      normalWithKey,
      hashFrequencys,
      acuteControlLevels,
      fitterControlLevels,
      fitterControlLevelsFunc,
      isAcute,
      isAcuteTitle,
      asthmaActionPlanTips,
      findTermChs,
    }
  }
  // export function emrStatus() {
  //   const store = useStore()
  //   // 是否放弃编辑
  //   function giveUpEditing() {
  //
  //     return new Promise((resolve, reject) => {
  //       if (store.getters.isEditing) {
  //         if (window.confirm('警告：\n 病历正在编辑中，是否确定放弃编辑？')) {
  //           // 放弃
  //           resolve(true)
  //         } else {
  //           reject(false)
  //         }
  //       } else {
  //         reject(false)
  //       }
  //     })
  //   }
  //   return {
  //     giveUpEditing,
  //   }
  // }
</script>
